<?php

class Rule_DatePeriod extends Rule
{
	public $field2;
	public $error_message = 'Конец периода не может быть раньше его начала';
	
	function __construct($name, $field2, $error_message = '')
	{
		$this->name = $name;
		$this->field2 = $field2;
		if ($error_message != '') $this->error_message = $error_message;
	}
	
	function Check($hash)
	{
		$arr = explode('.', $hash[$this->name]);
		if(sizeof($arr)!=3) return false;
		
		$day1=intval($arr[0]);
		$month1=intval($arr[1]);
		$year1=intval($arr[2]);
		
		$arr2 = explode('.',$hash[$this->field2]);
		if(sizeof($arr2)!=3) return false;
		
		$day2=intval($arr2[0]);
		$month2=intval($arr2[1]);
		$year2=intval($arr2[2]);
		
		if($year2<$year1) return false;
		if($year1<$year2) return true;
		
		if($month2<$month1) return false;
		if($month1<$month2) return true;
		
		if($day2<$day1) return false;
		
		return true;
	}
}